import java.util.concurrent.TimeUnit;

public class PoolFactoryImplementation<T> implements PoolFactory<T> {
    private ConnectionPool<T> connectionPool;

    @Override
    public ConnectionPool<T> newConnectionPool(ConnectionSource<T> src, int capacity) {
        return createConnectionPool(src, capacity, capacity, 0, TimeUnit.DAYS);
    }

    @Override
    public ConnectionPool<T> newConnectionPool(ConnectionSource<T> src,
                                               int min, int max,
                                               long keepAliveTime, TimeUnit unit) {
        return createConnectionPool(src, min, max, keepAliveTime, unit);
    }

    private ConnectionPool<T> createConnectionPool(ConnectionSource<T> src,
                                                   int min, int max,
                                                   long keepAliveTime, TimeUnit unit) {
        if (connectionPool == null) {
            connectionPool = new ConnectionPoolImplementation<T>(src, min, max, keepAliveTime, unit);
        }
        return connectionPool;
    }
}
